#
# Copyright (c) 2022 Winsider Seminars & Solutions, Inc.  All rights reserved.
#
# This file is part of System Informer.
#

if(MSVC AND CMAKE_C_COMPILER_ID STREQUAL "Clang")
    set(MSVC_CLANG ON)
else()
    set(MSVC_CLANG OFF)
endif()
if (MSVC AND NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
    set(MSVC_NOT_CLANG ON)
else()
    set(MSVC_NOT_CLANG OFF)
endif()

if(CMAKE_VS_PLATFORM_NAME)
    set(SI_PLATFORM "${CMAKE_VS_PLATFORM_NAME}")
elseif(CMAKE_GENERATOR_PLATFORM)
    if(CMAKE_GENERATOR_PLATFORM MATCHES "x64|AMD64|x86_64")
        set(SI_PLATFORM "x64")
    elseif(CMAKE_GENERATOR_PLATFORM MATCHES "ARM64|aarch64")
        set(SI_PLATFORM "ARM64")
    elseif(CMAKE_GENERATOR_PLATFORM MATCHES "i[3-6]86|[xX]86|Win32")
        set(SI_PLATFORM "Win32")
    else()
        message(FATAL_ERROR "Unsupported platform: ${CMAKE_GENERATOR_PLATFORM}")
    endif()
elseif(CMAKE_C_COMPILER_ARCHITECTURE_ID)
    if(CMAKE_C_COMPILER_ARCHITECTURE_ID MATCHES "x64|AMD64|x86_64")
        set(SI_PLATFORM "x64")
    elseif(CMAKE_C_COMPILER_ARCHITECTURE_ID MATCHES "ARM64|aarch64")
        set(SI_PLATFORM "ARM64")
    elseif(CMAKE_C_COMPILER_ARCHITECTURE_ID MATCHES "i[3-6]86|[xX]86|Win32")
        set(SI_PLATFORM "Win32")
    else()
        message(FATAL_ERROR "Unsupported platform: ${CMAKE_C_COMPILER_ARCHITECTURE_ID}")
    endif()
else()
    message(FATAL_ERROR "Unable to detect target platform.")
endif()
if(SI_PLATFORM STREQUAL "x64")
    set(SI_PLATFORM_SHORT "64")
elseif(SI_PLATFORM STREQUAL "ARM64")
    set(SI_PLATFORM_SHORT "ARM64")
elseif(SI_PLATFORM STREQUAL "Win32")
    set(SI_PLATFORM_SHORT "32")
else()
    message(FATAL_ERROR "Unexpected platform: ${SI_PLATFORM}")
endif()
